#include <Misc.au3>
#include <ScreenCapture.au3>
#include <..\utility.au3>

HotKeySet("{PAUSE}", "theExit")
HotKeySet("9", "theExit")

call("screenshot", "start")

$numsweeps = IniRead("settings.ini", "run", "numsweeps", 1)

$stormarmor = 1 ;storm armor is slot 1
$explosion = 1 ;archon explosion is slot 1
$teleport = 2 ;teleport is slot 2
$magicweapon = 3 ;magic weapon is slot 3
$familiar = 4 ;familiar is slot 4
$goldpiles = 5 ;Number of gold piles to pick up

$chestnum = 0;how many chests found
$chestlegnum = 0;how many legendaries we found in chest


While 1 
	processkey('70', "mousePos") ;F1
	processkey('71', "leorics") ;F2
	processkey('72', "getLegendaries") ;F3
	processkey('73', "repair") ;F4
	processkey('74', "findring") ;F5
	processkey('75', "findcolor") ;F6
	processkey('76', "checkdead") ;F7
	processkey('77', "castSpelltest") ;F8
	processkey('78', "checkdisco") ;F9
	processkey('79', "getGems") ;F10
WEnd

Func leorics()	
While 1
	Sleep($lagfactor)
	
	;Log Run Start
	call("logmessage", "Starting Run " & $runs)
	$runs = $runs + 1
	
	;Randomly take a break
	If $runs > 10 Then
		call("takebreak")
	EndIf
	
	;Buff
	Local $mode = Random(1,6,1)
	If $mode = 1 Then
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
	ElseIf $mode = 2 Then
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
	ElseIf $mode = 3 Then
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
	ElseIf $mode = 4 Then
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
	ElseIf $mode = 5 Then
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
	Else
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $familiar)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $magicweapon)
		call("fuzzysleep",Random(400,500,1))
		call("castSpell", $stormarmor)
	EndIf
	
	;Repair if needed
	If call("repair4")=0 Then
		;Move to portal
		call("fuzzyclick","left", 1205, 395)
	EndIf

	;Move mouse left of ourselves
	call("fuzzymove", 834, 500)

	call("fuzzysleep", Random(4000,4500,1))
	call("fuzzysleep", $lagfactor)

	
	
	;Meteor???
	Send("2")
	Sleep(Random(400,600,1))
	;comment below for hydra
	Send("2")
	Sleep(Random(400,600,1))
	Send("2")
	Sleep(Random(400,600,1))
	
	;Fire left
	call("fuzzyclick", "right", 881,482)
	Send("{SHIFTDOWN}")
	MouseDown("left")
	
	
	For $i=0 to $numsweeps step 1
		call("fuzzymove", Random(834,1108,1),Random(367,595,1))
		call("fuzzysleep", Random(0,200,1))
		call("castSpell", $explosion)
		call("fuzzysleep", Random(2000,2200,1))
	Next
	
	
	MouseUp("left")
	Sleep(Random(100,400,1))
	Send("{SHIFTUP}")
	
	call("fuzzysleep", Random(1400,1800,1))
	
	;Pick up Legendaries
	call("getLegendaries", 0)
	;call("getGems", 0)
	
	;Check if we are dead and just exit
	If call("checkdead", 0) = 1 Then
		call("exitgame", 0)
		ContinueLoop
	EndIf
	
	;Pick up gold
	;call("pickupGold", 1)
	
	call("exitgame")
	
	;Restart Script
WEnd	
	
EndFunc

Func FindDoor()
	;Find door
	Local $coord = PixelSearch(300, 0, 600, 100, 0x285EC5, 20)

	If Not @error Then
		MouseClick("left", $coord[0], $coord[1])
		fuzzysleep(2000 * $runspeed)
	EndIf
EndFunc